package com.hison.courseselectionsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hison.courseselectionsystem.domain.Course;
import com.hison.courseselectionsystem.domain.StudentCourse;
import com.hison.courseselectionsystem.mapper.StudentCourseMapper;
import com.hison.courseselectionsystem.service.StudentCourseService;
import com.hison.courseselectionsystem.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author hison
 * @description 针对表【student_course】的数据库操作Service实现
 * @createDate 2023-11-16 21:53:51
 */
@Service
public class StudentCourseServiceImpl extends ServiceImpl<StudentCourseMapper, StudentCourse> implements StudentCourseService {

    @Resource
    private StudentCourseMapper studentCourseMapper;

    @Override
    public Result choose(Integer stuid, Integer cid) {
        int i = studentCourseMapper.insert(new StudentCourse(stuid, cid));
        return i > 0 ? Result.ok("添加成功") : Result.fail("添加失败");
    }

    @Override
    public Result delete(Integer stuid, Integer cid) {
        QueryWrapper<StudentCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("student_id",stuid);
        wrapper.eq("course_id",cid);
        int i = studentCourseMapper.delete(wrapper);
        return i > 0 ? Result.ok("删除成功"):Result.fail("删除失败");
    }

    @Override
    public Result list(String stuid) {
        //查询自己选择的所有课程
        studentCourseMapper.quary(stuid);
        return null;
    }
}
